package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Dish;
import com.itheima.reggie.domain.Setmeal;
import com.itheima.reggie.domain.SetmealDish;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zsk
 * @create 2022-02-18-16:17
 */
@RestController
public class SetmealController {

    //依赖注入
    @Autowired
    private SetmealService setmealService;

    /*
    根据categoryid查询套餐数据
    Request URL: http://localhost:8081/setmeal/list?categoryId=1413386191767674881&status=1
    Request Method: GET
     */
    @Cacheable(value = "setmeal",key = "#categoryId")//查询使用Cacheable
    @GetMapping("/setmeal/list")
    public ResultInfo findByCategory(Long categoryId,Integer status){

        //调用service层查询
        List<Setmeal> setmealList = setmealService.findByCategory(categoryId,status);
        //返回结果
        return ResultInfo.success(setmealList);
    }

    /*
    点击套餐是显示套餐下具体菜品详情
    Request URL: http://localhost:8081/setmeal/dish/1415580119015145474
    Request Method: GET
     */
    @GetMapping("/setmeal/dish/{id}")
    public ResultInfo findById(@PathVariable long id){

        //调用service查询
        List<Dish> setmealList = setmealService.findById(id);

        //返回结果
        return ResultInfo.success(setmealList);
    }


}
